package com.yutel.socket.file;

import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.ServerSocket;
import java.net.Socket;

public class SendFile extends Thread {

	byte byteBuffer[] = new byte[1024];
	RandomAccessFile outFile;
	ServerSocket serSocket;
	OutputStream outputstream;
	Socket tempSocket;

	public static void main(String args[]) {
		SendFile sf = new SendFile();
		sf.start();
		System.out.println("wait for...");
	}

	public SendFile() {
		try {
			outFile = new RandomAccessFile("d:\\yuanyj.zip", "r");
			serSocket = new ServerSocket(9090);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void run() {
		try {
			tempSocket = serSocket.accept();
			outputstream = tempSocket.getOutputStream();
			int amount;
			while ((amount = outFile.read(byteBuffer)) != -1) {
				outputstream.write(byteBuffer, 0, amount);
			}
			System.out.println("Send File complete");
			outFile.close();
			tempSocket.close();
			serSocket.close();
		} catch (IOException e) {
		}
	}

}
